package cn.retalsystem.controller;

import cn.retalsystem.bean.Admin;
import cn.retalsystem.bean.Buding;
import cn.retalsystem.bean.Chewei;
import cn.retalsystem.service.BudingService;
import cn.retalsystem.service.CheweiService;
import cn.retalsystem.vo.CheweiVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @Author: 陈妙斌
 * @Date: 2019/10/31 15:13
 * @Version 1.0
 * @描述：
 */
@Controller
//@RequestMapping("/chewei")
public class CheweiController {
    @Autowired
    CheweiService cheweiService;
    @Autowired
    BudingService budingService;


//    @RequestMapping("/init")
//    public String toRoomView(Model model,String bname,Integer type){
//        //获取楼栋信息，填充下拉选择框
////        List<Buding> budings = budingService.selectAllBuding();
////        model.addAttribute("bs",budings);
//        //获取房间信息总数,用于渲染分页
////        Integer count = roomService.selectCountByExample(rname, budingId);
////        model.addAttribute("count",count);
//        //将条件查询的信息存入mode，用于分页异步请求
//        model.addAttribute("bname",bname);
//        model.addAttribute("type",type);
//        System.out.println("ok");
//        return "parking_managent";
//    }
    @RequestMapping("/parking")
    public  String test(Model model ,String bname,Integer type){
        int h = cheweiService.hcconut(bname,type);
        model.addAttribute("count",h);
        model.addAttribute("bname",bname);
        model.addAttribute("type",type);
        return "parking_managent";
    }




    @RequestMapping("/table")
    @ResponseBody
    public List sjjh(Integer page, Integer limit,String bname,Integer type){


        return cheweiService.selectCheweiByExample(page,limit,bname,type);
    }
    /**
     * 删除数据
     *  fjid 房间id
     * @return
     */
    @RequestMapping("/del")
    @ResponseBody
    public void del(int  id){


        System.out.println(id);

       cheweiService.deltableinfo(id);
        System.out.println("删除成功");



    }
    @RequestMapping("/delChewiById")
    @ResponseBody
    public boolean delChewei(@RequestBody Map<String,List<Integer>> map){
        List<Integer> ids = map.get("ids");
      cheweiService.delCheweiById(ids);
        return true;
    }
    @RequestMapping("/getCheweiById")
    @ResponseBody
    public Chewei getCheweiById(Integer id){
        return cheweiService.selectCheweiById(id);
    }

    @RequestMapping("/updateChewei")
    @ResponseBody
    public boolean updateRoom(@RequestBody Chewei chewei){
        cheweiService.updateChewei(chewei);
        return true;
    }
    @RequestMapping("/addChewei")
    @ResponseBody
    public boolean addRoom(@RequestBody Chewei chewei, HttpSession session){
        Admin admin = (Admin) session.getAttribute("admin");
        cheweiService.addChewei(chewei,admin.getId());
        return true;
    }
//    @RequestMapping("/getCheweiByExample")
//    @ResponseBody
//    public List<CheweiVo> getCheweiVoByExample(String bname,Integer type){
//        return cheweiService.selectCheweiByExample(bname,type);
//    }
}
